import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

export default new Vuex.Store({
    state: {
        show: false, //1.控制手机号前缀弹窗是否显示
        songdata: false, //2.底部歌曲播放栏是否显示
        singShow: false, //3.歌曲播放详情页是否显示

        audioControl: {
            //4.歌曲控制项
            musicData: {}, //单个歌曲数据
            isPlaying: Boolean, //4.1是否暂停
            musicDt: Number, //4.2歌曲时长秒
            alreadyPlay: Number, //4.3歌曲已经播放的时秒
        },

        misicList: {}, //点击的类型歌曲list
    },
    mutations: {
        //设置2显示或隐藏.
        alterSongShow(state, boolean) {
            state.songShow = boolean;
        },
        //设置3显示或隐藏.
        alterSingShow(state, boolean) {
            state.singShow = boolean;
        },

        //设置4.1播放还是暂停
        isPlaying(state, boolean) {
            state.audioControl.isPlaying = boolean;
        },

        //设置4.2歌曲时长秒
        musicDt(state, num) {
            state.audioControl.musicDt = num;
        },

        //设置4.3歌曲播放到多少秒
        alreadyPlay(state, num) {
            state.audioControl.alreadyPlay = num;
        },

        //设置点击的类型歌曲list
        misicList(state, { list, index }) {
            state.misicList = list;
            console.log(index)
            console.log(list)
            list.forEach(element => {
                if (element.resourceId == index) {
                    state.audioControl.musicData = element;

                    let content = new Promise((resolve, reject) => {
                        this.axios
                            .get("http://localhost:3000/song/url", {
                                params: {
                                    id: index
                                },
                            })
                            .then((res) => {

                                resolve(data);
                                this.getmusicItem(songID.resourceId);
                            })
                            .catch((err) => {
                                reject(err);
                                console.log(err);
                            });
                    });

                    return
                }
            });
        },
    },

    //和mutations一样,不过是异步的
    actions: {},
    modules: {},
});